package com.yumei.trader.gym.raw;

import android.annotation.SuppressLint;
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;

import java.util.HashMap;

public class TradeSoundPool {

	public static final int ACTION_BUTTON = 1;
	public static final int ACTION_BUY = 2;
	public static final int ACTION_SELL = 3;

	public static final int GAMEOVER_WIN = 4;
	public static final int GAMEOVER_FAIL = 5;
	public static final int GAMEOVER_RESULT = 6;

	private int volume ;
	
	private SoundPool pools;

	private HashMap<Integer,Integer> soundPoolMap;

	public static boolean status = true;

	@SuppressLint("UseSparseArrays")
	public TradeSoundPool(Context context){

		pools = new SoundPool(10,AudioManager.STREAM_MUSIC,100);
		soundPoolMap = new HashMap<>();
		
		AudioManager am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
		
		volume = am.getStreamVolume(AudioManager.STREAM_MUSIC);
	}
	
	public  void setStatus(boolean status){
		this.status = status;
	}
	
	
	public void loadSound(Context context,int id,int resId){
		soundPoolMap.put(new Integer(id), new Integer(pools.load(context, resId, 1)));
	}
	

	public void play(int id){

		System.out.print("sound status = "+status);

		if(status){
			pools.play(soundPoolMap.get(id).intValue(), volume*0.05f, volume*0.05f, 1, 0, 1.0f);
		}
	}
}


